package com.example.shiyansan.controller.user;

import com.example.shiyansan.entity.Book;
import com.example.shiyansan.result.Result;
import com.example.shiyansan.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user/book")
public class BookController {
    /**
     * 展示图书列表
     */

    @Autowired
    private BookService bookService;

    @GetMapping("/list")
    public Result<List<Book>> BookList(){
        List<Book> bookList = bookService.findBookList();
        return Result.success(bookList);
    }

    @GetMapping("/detail/{id}")
    public Result<Book> detail(@PathVariable int id){
        Book book = bookService.findBookById(id);
        return Result.success(book);
    }

    @PutMapping("/update/{id}")
    public Result<String> update(@PathVariable int id, @RequestBody Book book) {
        book.setBookId(id);
        bookService.updateBook(book);
        return Result.success("更新成功");
    }
}
